package com.office;

import com.office.reader.ExcelReader;
import com.office.reader.HtmlReader;
import com.office.reader.IcepdfReader;
import com.office.reader.PptReader;
import com.office.reader.TextReader;
import com.office.reader.WordReader;
import com.office.util.FileUtils;

public class ReaderFactory {

	private static String IMG_SAVE_PATH = "F:/test/img/";

	/**
	 * 获取文件保存的路径，手动拼接路径
	 * 
	 * @param fileType
	 * @param fileName
	 * @return
	 */
	public static String getImgSavePath(String fileType, String fileName) {
		return IMG_SAVE_PATH + fileType + "/" + fileName + "/";
	}

	/**
	 * 根据不同的文件类型，调用相应的文件处理方法
	 * 
	 * @param suffixName
	 * @param filePath
	 */
	public static void createReader(String suffixName, String filePath) {

		if ("docx".endsWith(suffixName) || "doc".endsWith(suffixName)) {
			FileUtils.createDirectory(getImgSavePath("word",
					FileUtils.getFileName(filePath)));
			WordReader.readWord(filePath,
					getImgSavePath("word", FileUtils.getFileName(filePath)));
		}

		if ("ppt".endsWith(suffixName)) {
			FileUtils.createDirectory(getImgSavePath("ppt",
					FileUtils.getFileName(filePath)));
			PptReader.readPpt(filePath,
					getImgSavePath("ppt", FileUtils.getFileName(filePath)));
		}

		if ("pdf".endsWith(suffixName)) {
			FileUtils.createDirectory(getImgSavePath("pdf",
					FileUtils.getFileName(filePath)));
			IcepdfReader.readPdf(filePath,
					getImgSavePath("pdf", FileUtils.getFileName(filePath)));
		}

		if ("txt".endsWith(suffixName)) {
			TextReader.readText(filePath);
		}

		if ("xls".endsWith(suffixName) || "xlsx".endsWith(suffixName)) {
			new ExcelReader().getExcelToString(filePath);
		}
		
		if("html".endsWith(suffixName)||"htm".endsWith(suffixName)){
			HtmlReader.readHtml(filePath);
		}
	}

}
